<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加旅行社入住</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">添加旅行社入住</div>
                <div class="layui-card-body">
                    <form class="layui-form" action="" lay-filter="component-form-group">

                        <div class="layui-form-item">
                            <label class="layui-form-label">旅行社名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="team_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">旅行社电话</label>
                            <div class="layui-input-block">
                                <input type="text" name="team_phone" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">常用手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="send_tel" placeholder="用户商户接收账号和密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" id="area-picker">
                            <div class="layui-form-label">景点地址</div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="province" class="province-selector" id="province" data-value="北京市" lay-filter="province-1">
                                    <option value="" >请选择省</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="city" class="city-selector" id="city" data-value="北京市" lay-filter="city-1">
                                    <option value="" >请选择市</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="county" class="county-selector" id="county" data-value="东城区" lay-filter="county-1">
                                    <option value="" >请选择区</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">详细地址</label>
                            <div class="layui-input-block">
                                <input type="text" name="dizhi" placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">身份证照片</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="guide_card_img1" id="guide_card_img1">
                                <button type="button" class="layui-btn" id="guide_card_thumb1">身份证正面照片</button>

                            </div>
                            <div  class="layui-input-block" id="upload_thumb_img_div1" style="display: none;">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="upload_thumb_img1" style="width:200px;height:140px;">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">身份证照片</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="guide_card_img2" id="guide_card_img2">
                                <button type="button" class="layui-btn" id="guide_card_thumb2">身份证反面照片</button>

                            </div>
                            <div  class="layui-input-block" id="upload_thumb_img_div" style="display: none;">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="upload_thumb_img" style="width:200px;height:140px;">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">营业执照</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="team_license_image" id="guide_pic">
                                <button type="button" class="layui-btn" id="guide_pic_thumb">上传营业执照</button>

                            </div>
                            <div  class="layui-input-block" id="upload_thumb_img_div2" style="display: none;">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="upload_thumb_img2" style="width:200px;height:140px;">
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">景点实景图</label>
                            <div class="layui-input-block">
                                <input type="hidden" name="team_image" id="live_action">
                                <button type="button" class="layui-btn" id="guide_pic_thumb4">上传景点实景图</button>

                            </div>
                            <div  class="layui-input-block" id="upload_thumb_img_div4" style="display: none;">
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="upload_thumb_img4" style="width:200px;height:140px;">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-layout-admin">
                            <div class="layui-input-block">
                                <div class="layui-inline" style="left: 0;">
                                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="addsubmit">提交</button>
                                    <a class="layui-btn layui-btn-primary prex" data-type="prex">返回</a>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>



<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','set','upload','layarea'], function(){
        $ = layui.jquery;
        var  admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form
            , layarea = layui.layarea
            ,upload=layui.upload;

        form.render(null,'component-form-group');
        layarea.render({
            elem: '#area-picker',

            change: function (res) {
                //选择结果
                $("#province").attr('data-value');
                $("#city").attr('data-value');
                $("#county").attr('data-value');
            }
        });
        //添加提交
        form.on('submit(addsubmit)', function(data){
            //正则手机号
            var myreg = /^1\d{10}$/;
            if(!myreg.test($('[name=send_tel]').val())){
                layer.msg('请输入正确的手机格式');
                return false;
            }


            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });

            $.ajax({
                url: "{:url('Merchant/addTeam')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(data){
                    if (data.code === 0) {
                        layer.msg('添加成功',{icon:1,time:2000},function(){
                            window.location.href = "{:url('Merchant/team')}";
                        });
                    }else if(data.code === 2){
                        layer.close(loading);
                        layer.msg('添加失败',{icon:2,time:1000})
                    }else if(data.code === 1){
                        layer.close(loading);
                        layer.msg(data.message,{icon:2,time:1000})
                    }else{
                        layer.close(loading);
                        layer.msg(data.message,{icon:2,time:1000})
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });




        //身份证正面照片上传
        var uploadInst = upload.render({
            elem: '#guide_card_thumb1'
            ,url: "{:url('Common/upload')}"
            ,before: function(obj){
                $('#upload_thumb_img_div1').show();
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#upload_thumb_img1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){

                if (res.code == 1){
                    $('#guide_card_img1').val(res.data);
                    return layer.msg(res.msg);
                }else{
                    return layer.msg(res.msg);
                }
            }
        });

        //身份证反面照片上传
        var uploadInst = upload.render({
            elem: '#guide_card_thumb2'
            ,url: "{:url('Common/upload')}"
            ,before: function(obj){
                $('#upload_thumb_img_div').show();
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#upload_thumb_img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){

                if (res.code == 1){
                    $('#guide_card_img2').val(res.data);
                    return layer.msg(res.msg);
                }else{
                    return layer.msg(res.msg);
                }
            }
        });

        //导游证照片上传
        var uploadInst = upload.render({
            elem: '#guide_pic_thumb'
            ,url: "{:url('Common/upload')}"
            ,before: function(obj){
                $('#upload_thumb_img_div2').show();
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#upload_thumb_img2').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){

                if (res.code == 1){
                    $('#guide_pic').val(res.data);
                    return layer.msg(res.msg);
                }else{
                    return layer.msg(res.msg);
                }
            }
        });

        //导游证照片上传
        var uploadInst = upload.render({
            elem: '#guide_pic_thumb4'
            ,url: "{:url('Common/upload')}"
            ,before: function(obj){
                $('#upload_thumb_img_div4').show();
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#upload_thumb_img4').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){

                if (res.code == 1){
                    $('#live_action').val(res.data);
                    return layer.msg(res.msg);
                }else{
                    return layer.msg(res.msg);
                }
            }
        });


        var $ = layui.$, active = {
            prex:function(){
                layer.confirm('确认取消本次编辑并返回吗？',function(){
                    window.location.href="{:url('Merchant/team')}";
                });
            }
        };

        $('.prex').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>

</body>
</html>